package com.umgsai.wx.backend.test;

public class IntReverse {

    public static void main(String[] args) {
//        System.out.println(reverse(34522235));
//        System.out.println(reverse(Integer.MAX_VALUE));
        System.out.println(reverse(Integer.MIN_VALUE));
    }

    public static int reverse(int x) {
        int result = 0;
        int prevResult;
        while (x != 0) {
            prevResult = result;
            result = result * 10 + x % 10;
            if (result / 10 != prevResult) {
                return 0;
            }
            x /= 10;
        }
        return result;
    }
}
